package com.tech.connect.fragment;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;

import com.ksy.common.dialog.ItemsDialog;
import com.ksy.common.utils.BaseAdapter;
import com.ksy.common.utils.BaseHolder;
import com.ksy.common.view.HLineDivider;
import com.tech.connect.R;
import com.tech.connect.activity.OtherInfoActivity;

import java.util.ArrayList;
import java.util.List;

public class MainTabMessageFragment extends BaseFragment {

    private RecyclerView recycler;
    private List<String> allUser = new ArrayList<>();
    private BaseAdapter<String, BaseHolder> adapter;

    @Override
    protected boolean isShowHeadBar() {
        return true;
    }

    @Override
    protected boolean isFullStateBar() {
        return true;
    }

    @Override
    public View onCreateView(LayoutInflater inflater) {
        View view = inflater.inflate(R.layout.fragment_main_tab_message, null);
        return view;
    }

    @Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        getHeadBar().setTitle("消息").setRightIcon(R.drawable.icon_more, new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                ItemsDialog itemsDialog = new ItemsDialog<>(activity, new String[]{"添加好友", "发起群聊"}, new ItemsDialog.ItemChooseListener() {
                    @Override
                    public void choose(ItemsDialog dialog, int position) {
                        dialog.dismiss();
                        if (position != -1) {
                            showToast("pos" + position);
                        }
                    }
                });
                itemsDialog.show();
            }
        });
        initView(view);
        loadData();
        initAllCityAdapter();
    }

    private void initView(View view) {
        recycler = view.findViewById(R.id.recycler);
        recycler.addItemDecoration(new HLineDivider());
        recycler.setLayoutManager(new LinearLayoutManager(activity, LinearLayoutManager.VERTICAL, false));
    }

    private void loadData() {

    }

    private void initAllCityAdapter() {
        if (adapter == null) {
            adapter = new BaseAdapter<String, BaseHolder>(R.layout.item_layout_message, allUser, 90) {
                @Override
                protected void convert(BaseHolder helper, int position) {
                    TextView tvUser = helper.getView(R.id.tvUser);
                    tvUser.setText("娃哈哈");
                }
            };
            adapter.setOnItemClickListener(new BaseAdapter.OnItemClickListener() {
                @Override
                public void onItemClick(View view, int position) {
                    jump2Activity(OtherInfoActivity.class);
                }
            });
            recycler.setAdapter(adapter);
        }
        adapter.notifyDataSetChanged();
    }
}
